package FactoryMethod;

import java.sql.SQLException;

import database.Hsqldb;

public class DatabaseProduct extends Product{
	
	private Hsqldb db;
	
	public DatabaseProduct() { }
	protected DatabaseProduct(String query){object = "Obiekt z bazy danych"; this.query=query;}
	
	
	@Override
	public void getRow(int row) {
		//System.out.println(row +" linijka to:");
		System.out.println("DatabaseProduct.getRow(" + row + ")");
		db.queryDatabase(row);

	}

	@Override
	public void open(){
		System.out.println("DatabaseProduct.open()");
        try {

            db = new Hsqldb(query);
        } catch (Exception ex1) {
            ex1.printStackTrace();    // could not start db
            return;                   // bye bye
        }
    	db.generateDatabase(db);
    	db.fillupDatabase();


	}

	@Override
	public void close() {

		System.out.println("DatabaseProduct.close()");
    	db.cleanDatabase();
    	db.closeDatabase();
	}

	@Override
	public Product createProduct(String query) {
		return new DatabaseProduct(query);
	}
}


